home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / std / c / 55 < prev    next >
Encoding:
Internet Message Format  |  1996-08-06  |  1.9 KB

  1. Path: engnews2.Eng.Sun.COM!lupa!corbett
  2. From: corbett@lupa.eng.sun.com (Robert Corbett)
  3. Newsgroups: comp.std.c
  4. Subject: Re: Undefined result vs. int's holding undefined values.
  5. Date: 9 Jan 1996 06:00:38 GMT
  6. Organization: Sun Microsystems Computer Corporation
  7. Message-ID: <4ct0a6$eom@engnews2.Eng.Sun.COM>
  8. References: <4ck70b$rd7@news.informix.com> <4cmg0s$1mb@der.twinsun.com> <oZA8wQ9ytpjN084yn@csn.net> <4cpv1n$apm@der.twinsun.com>
  9. NNTP-Posting-Host: lupa.eng.sun.com
  10. Cc: 
  11.  
  12. In article <4cpv1n$apm@der.twinsun.com>,
  13. Paul Eggert <eggert@twinsun.com> wrote:
  14. >thads@csn.net (Thad Smith) writes:
  15. >
  16. >> it is possible to rewrite the function so that it doesn't
  17. >> invoke undefined behavior
  18. >
  19. >Yes.  But it slows things down measurably for an interpreter to use
  20. >such a clumsy method for integer overflow detection.  The (x + y < x)
  21. >!= (y < 0) method requires a comparison, an exclusive OR of the
  22. >comparison result bit with a sign bit, and a conditional branch.
  23. >The method you suggested requires a comparison, a conditional branch, a
  24. >subtraction, another comparison, and another conditional branch.
  25. >
  26. >Since this is comp.std.c, I'll mention that the (x + y < x) != (y < 0) method
  27. >and Daniel Wood's example both port to any C implementation
  28. >claiming conformance to LIA-1 (ISO/IEC 10967-1:1994(E),
  29. >`Information technology -- Language independent arithmetic -- Part 1:
  30. >Integer floating point arithmetic' <ftp://crl.dec.com/pub/misc/lia-1-dis.ps.Z>)
  31. >if INT_MODULO is true (which is the only plausible value for INT_MODULO
  32. >for real-world C compilers).  I doubt whether Wood's compiler vendor
  33. >claims LIA-1 conformance today, but this may become more important in
  34. >the future, and perhaps Wood can point his vendor at LIA-1 and say that
  35. >it's time to read the handwriting on the wall.
  36.  
  37. It will also be true for any implementation conforming to IEEE Std 1754.
  38. I urge all users to insist that their vendors' implementations conform to
  39. IEEE Std 1754.
  40.  
  41.                     Sincerely,
  42.                     Robert Corbett
  43.